﻿Imports MySql.Data.MySqlClient
Public Class Form3
    Dim cmd As MySqlCommand
    Dim dt As New DataTable
    Dim con As MySqlConnection
    Dim bsource As BindingSource
    Dim sda As MySqlDataAdapter

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Show()
        Me.Hide()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        con = New MySqlConnection
        con.ConnectionString = "server=localhost;userid=root;password=;database=library_database "
        Dim sda As New MySqlDataAdapter
        Dim bsource As New BindingSource

        Try
            con.Open()
            Dim query As String
            query = "select book_issue_no,issue_book,return_book,reserve_book,book_borrower_details from library_database.book_borrower "
            cmd = New MySqlCommand(query, con)
            sda.SelectCommand = cmd
            sda.Fill(dt)
            bsource.DataSource = dt
            DataGridView1.DataSource = bsource
            sda.Update(dt)
            con.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            con.Close()
        End Try
    End Sub

    Private Sub txtsearch1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch1.TextChanged
        Dim dv As New DataView(dt)
        dv.RowFilter = String.Format("book_borrower_details like '%{0}%' ", txtsearch1.Text)
        DataGridView1.DataSource = dv
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        dt.Clear()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.Close()
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub
End Class